// api/family/ai-project.ts
import { api } from '@/api/request'
import type { PageData, PageQuery } from '@/types'

// AI项目信息模型
export interface AIProjectInfo {
    id: number
    name: string
    type: string  // 项目类型: ml, dl, nlp, cv, speech, recommendation
    difficulty: number  // 难度等级: 1-入门, 2-中级, 3-高级
    description: string
    github_url: string
    demo_url: string
    technologies: string  // 技术栈，逗号分隔
    tags: string  // 标签，逗号分隔
    stars: number  // 收藏数
    views: number  // 浏览量
    user_id: number
    family_id: number
    created_at: string
    updated_at: string
}

// AI项目查询参数
export interface AIProjectQuery extends PageQuery {
    name?: string
    type?: string
    difficulty?: number
}

// 创建AI项目请求参数
export interface CreateAIProjectRequest {
    name: string
    type: string
    difficulty: number
    description?: string
    github_url?: string
    demo_url?: string
    technologies?: string
    tags?: string
    user_id: number
    family_id: number
}

// 更新AI项目请求参数
export interface UpdateAIProjectRequest {
    name?: string
    type?: string
    difficulty?: number
    description?: string
    github_url?: string
    demo_url?: string
    technologies?: string
    tags?: string
    stars?: number
    views?: number
}

// AI项目API接口定义
export const AIProjectApi = {
    // 获取AI项目列表
    getProjectList: (params: AIProjectQuery) => {
        return api.get<PageData<AIProjectInfo>>('/system/ai-project/list', { params })
    },
    
    // 获取AI项目详情
    getProjectDetail: (id: number) => {
        return api.get<AIProjectInfo>(`/system/ai-project/${id}`)
    },
    
    // 创建AI项目
    createProject: (data: CreateAIProjectRequest) => {
        return api.post<AIProjectInfo>('/system/ai-project/create', data)
    },
    
    // 更新AI项目
    updateProject: (id: number,  data:UpdateAIProjectRequest) => {
        return api.put<AIProjectInfo>(`/system/ai-project/${id}`, data)
    },
    
    // 删除AI项目
    deleteProject: (id: number) => {
        return api.delete(`/system/ai-project/${id}`)
    },
    
    // 增加浏览量
    increaseViews: (id: number) => {
        return api.put<AIProjectInfo>(`/system/ai-project/${id}/views`)
    },
    
    // 增加收藏数
    toggleStar: (id: number) => {
        return api.put<AIProjectInfo>(`/system/ai-project/${id}/star`)
    }
}
